package com.fang.tcptest;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class TestSocket extends Thread {
    private Socket socket;

    public TestSocket() {
        super("客户端：");
    }

    @Override
    public void run() {
        try {
            socket = new Socket("127.0.0.1",8090);
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            while(true) {
                Scanner sc = new Scanner(System.in);
                String strWrite = sc.next();
                bw.write(this.getName()+strWrite);
                bw.newLine();
                System.out.println(this.getName()+strWrite);
                bw.flush();
                ///////////////////////接收//////////////////
                BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                String strRead =  br.readLine();
                System.out.println(strRead);
            }
            } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
